<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <title>墨点艺术</title>
    <link type="text/css" rel="stylesheet" href="css/style.css"/>
</head>
<body>
<div class="body">
    <div class="header">
        <span>墨点快讯</span>
    </div>
    <div class="content flex1">
        <div class="handle">
            <a href="javascript:;" class="back"></a>
            <a href="javascript:;" class="filter"></a>
        </div>
        <div class="artist-search">
            <div class="search">
                <input type="text" placeholder="搜搜你想看到的艺术家吧~">
            </div>
        </div>
        <div class="artist-list">
            <div class="module artist-item">
                <div class="top">
                    <img src="images/banner.jpg" alt="" class="head">
                    <div class="center flex1">
                        <p>吴晓伟 | 北京</p>
                        <p class="b">擅长：书法、写生</p>
                        <p class="num">作品 399</p>
                    </div>
                    <div class="right">
                        <div class="heart"></div>
                        <p>热度 199.99万</p>
                    </div>
                </div>
                <div class="thumb-box">
                    <a href="javascript:;" class="thumb">
                        <img src="images/banner.jpg" alt="">
                    </a>
                    <a href="javascript:;" class="thumb">
                        <img src="images/banner.jpg" alt="">
                    </a>
                    <a href="javascript:;" class="thumb">
                        <img src="images/banner.jpg" alt="">
                    </a>
                </div>
            </div>
            <div class="module artist-item">
                <div class="top">
                    <img src="images/banner.jpg" alt="" class="head">
                    <div class="center flex1">
                        <p>吴晓伟 | 北京</p>
                        <p class="b">擅长：书法、写生</p>
                        <p class="num">作品 399</p>
                    </div>
                    <div class="right">
                        <div class="heart collect"></div>
                        <p>热度 199.99万</p>
                    </div>
                </div>
                <div class="thumb-box">
                    <a href="javascript:;" class="thumb">
                        <img src="images/banner.jpg" alt="">
                    </a>
                    <a href="javascript:;" class="thumb">
                        <img src="images/banner.jpg" alt="">
                    </a>
                    <a href="javascript:;" class="thumb">
                        <img src="images/banner.jpg" alt="">
                    </a>
                </div>
            </div>
            <div class="module artist-item">
                <div class="top">
                    <img src="images/banner.jpg" alt="" class="head">
                    <div class="center flex1">
                        <p>吴晓伟 | 北京</p>
                        <p class="b">擅长：书法、写生</p>
                        <p class="num">作品 399</p>
                    </div>
                    <div class="right">
                        <div class="heart"></div>
                        <p>热度 199.99万</p>
                    </div>
                </div>
                <div class="thumb-box">
                    <a href="javascript:;" class="thumb">
                        <img src="images/banner.jpg" alt="">
                    </a>
                    <a href="javascript:;" class="thumb">
                        <img src="images/banner.jpg" alt="">
                    </a>
                    <a href="javascript:;" class="thumb">
                        <img src="images/banner.jpg" alt="">
                    </a>
                </div>
            </div>
            <div class="module artist-item">
                <div class="top">
                    <img src="images/banner.jpg" alt="" class="head">
                    <div class="center flex1">
                        <p>吴晓伟 | 北京</p>
                        <p class="b">擅长：书法、写生</p>
                        <p class="num">作品 399</p>
                    </div>
                    <div class="right">
                        <div class="heart"></div>
                        <p class="num">热度 199.99万</p>
                    </div>
                </div>
                <div class="thumb-box">
                    <a href="javascript:;" class="thumb">
                        <img src="images/banner.jpg" alt="">
                    </a>
                    <a href="javascript:;" class="thumb">
                        <img src="images/banner.jpg" alt="">
                    </a>
                    <a href="javascript:;" class="thumb">
                        <img src="images/banner.jpg" alt="">
                    </a>
                </div>
            </div>
            <div class="module artist-item">
                <div class="top">
                    <img src="images/banner.jpg" alt="" class="head">
                    <div class="center flex1">
                        <p>吴晓伟 | 北京</p>
                        <p class="b">擅长：书法、写生</p>
                        <p class="num">作品 399</p>
                    </div>
                    <div class="right">
                        <div class="heart"></div>
                        <p>热度 199.99万</p>
                    </div>
                </div>
                <div class="thumb-box">
                    <a href="javascript:;" class="thumb">
                        <img src="images/banner.jpg" alt="">
                    </a>
                    <a href="javascript:;" class="thumb">
                        <img src="images/banner.jpg" alt="">
                    </a>
                    <a href="javascript:;" class="thumb">
                        <img src="images/banner.jpg" alt="">
                    </a>
                </div>
            </div>
        </div>
        <!-- 筛选 -->
        <div class="filter-panel">
            <div class="mask"></div>
            <form action="" class="panel filter-form">
                <div class="btns">
                    <span>筛选</span>
                    <span class="btnn" onclick="filterSubmit()">完成</span>
                    <span class="btnn" onclick="filterClear()">清除</span>
                </div>
                <ul class="list">
                    <!-- 筛选列表 -->
                </ul>
                <div class="sub-list">
                    <!-- 筛选子列表 -->
                </div>
            </form>
        </div>
    </div>
</div>
<script src="js/jquery-1.9.1.min.js"></script>
<script>
    var filterDatas = []; //筛选数据 全局
    // 点击筛选按钮
    $('.filter').click(function(){
        // $.get('api.json', function(res){
            var res = {
                "status": 202,
                "message": "success",
                "data": [
                    {
                        "channel": "艺术分类", // 列表名称
                        "name": "type", // input框的name
                        "list": [  // 二级列表
                            {
                                "value": 1,
                                "name": "数学"
                            },
                            {
                                "value": 2,
                                "name": "语文"
                            }
                        ]
                    },
                    {
                        "channel": "籍贯1",
                        "name": "addr", // input框的name
                        "list": [
                            {
                                "value": 1,
                                "name": "山西"
                            },
                            {
                                "value": 2,
                                "name": "北京"
                            },
                            {
                                "value": 3,
                                "name": "西藏"
                            }
                        ]
                    },
                ]
            }
            if(res.status == 202){
                filterDatas = res.data;
                var _filterListHtml = '';
                for(var i=0;i<filterDatas.length;i++){
                    _filterListHtml += '<li data-type="'+i+'"><span class="flex1">'+filterDatas[i].channel+'</span><input type="hidden" name="'+filterDatas[i].name+'"><span class="s"></span><img src="images/more.png" alt=""></li>';
                }
                $('.filter-panel .list').html(_filterListHtml);
            }
        // })
        var height = $(window).height() - $(window).width() / 10;
        $('.filter-panel').css('height', height).show().find('.panel').animate({right:0});
    })
    // 点击筛选列表 第一层
    $('.filter-panel .list').on('click', 'li', function(){
        var _index = $(this).index();
        var _subDatas = filterDatas[_index].list;
        var _subHtml = '<p class="tit">'+filterDatas[_index].channel+'</p><ul><li data-value="0" data-channel="'+_index+'" class="select"><span>全部</span><div></div></li>';
        for(var i=0;i<_subDatas.length;i++){
            _subHtml += '<li data-value="'+_subDatas[i].value+'" data-channel="'+_index+'"><span>'+_subDatas[i].name+'</span><div></div></li>';
        }
        _subHtml += '</ul>'
        $('.filter-panel .sub-list').html(_subHtml).animate({right:0});
        // 如果已有值
        var _inputVal = $(this).find('input').val();
        if(_inputVal){
            $('.filter-panel .sub-list li').removeClass('select');
            for(var i=0;i<$('.filter-panel .sub-list li').length;i++){
                if($('.filter-panel .sub-list li').eq(i).data('value') == _inputVal){
                    $('.filter-panel .sub-list li').eq(i).addClass('select');
                }
            }
        }
    })
    // 点击筛选选择列表 第二层  子列表
    $('.filter-panel .sub-list').on('click', 'li', function(){
        var _channelIndex = $(this).data('channel');
        var _selectValue = $(this).data('value');
        var _selectName = $(this).find('span').html();
        $('.filter-panel .list li').eq(_channelIndex).find('input').val(_selectValue);
        $('.filter-panel .list li').eq(_channelIndex).find('.s').html(_selectName);
        $('.filter-panel .sub-list').animate({right: '-80vw'})
    })
    // 点击返回上一页 第二层  子列表
    $('.filter-panel .sub-list').on('click', '.tit', function(){
        $('.filter-panel .sub-list').animate({right: '-80vw'})
    })
    // 点击筛选面板的遮罩部分隐藏
    $('.filter-panel .mask').click(function(){
        filterPanelHide();
    })
    // 筛选面板隐藏
    function filterPanelHide(){
        $('.filter-panel').hide().find('.panel').animate({right:'-80vw'}).find('.sub-list').css({right: '-80vw'});
    }
    // 点击提交
    function filterSubmit(){
        $('.filter-form').submit();
    }
    // 点击清除
    function filterClear(){
        $('.filter-form').find('input').val('');
        $('.filter-form').find('.s').html('');
    }
</script>
</body>
</html>